package com.codi.api.controller.organ;

import com.codi.api.security.UserUtil;
import com.codi.base.log.annotation.Loggable;
import com.codi.base.util.ExceptionUtil;
import com.codi.bus.core.resultModel.BaseResult;
import com.codi.bus.core.resultModel.NTradingRecordListResult;
import com.codi.bus.core.resultModel.WTradingRecordListResult;
import com.codi.bus.core.service.organ.OrganApplyRecordService;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author lvgo
 * @version 1.0
 * @Description: 机构交易记录
 * @date 2018/5/8 16:22
 */
@RestController
@RequestMapping("/organ/applyRecord")
@Slf4j
public class OrganApplyRecordController {


    @Resource
    private OrganApplyRecordService organApplyRecordService;


    /**
     * 交易记录详情
     * @param profileId
     * @param allotNo
     * @return
     */
    @GetMapping("/fundDetail")
    @Loggable
    public BaseResult fundDetail(String profileId, String allotNo) {
        BaseResult baseResult = organApplyRecordService.queryFundDetail(profileId, allotNo);
        return baseResult;
    }

    /**
     * 资产--基金交易记录
     *  企业宝和基金 共同使用
     * @param fundCode  基金代码 非必
     * @param queryType 业务类型, all 全部 onWay 进行中
     * @return
     */
    @GetMapping("/fundRecord")
    @Loggable
    public BaseResult fundRecord(String profileId, String fundCode, @NonNull String queryType, String business, Integer requestNum, Integer beginNum, String allotNo, Boolean isOrganBao) {
        NTradingRecordListResult nTradingRecordListResult = null;
        try {
            nTradingRecordListResult = organApplyRecordService.queryFundRecord(profileId, fundCode, queryType, UserUtil.getLoginUserId(), beginNum, requestNum, business, allotNo,isOrganBao);
        } catch (Exception e) {
            ExceptionUtil.logError(log, "queryApplys - Exception:", e);
        }
        return nTradingRecordListResult;
    }


    /**
     * 资产--瑞富宝交易记录
     * 不再使用
     * @param fundCode  瑞富宝代码 非必
     * @param queryType 业务类型, all 全部 onWay 进行中
     * @return
     */
    @GetMapping("/ruifubaoRecord")
    @Loggable
    public BaseResult ruifubaoRecord(String profileId, String fundCode, @NonNull String queryType, String business, Integer requestNum, Integer beginNum, String allotNo) {
        WTradingRecordListResult wTradingRecordListResult = null;
        try {
            wTradingRecordListResult = organApplyRecordService.queryRuifubaoRecord(profileId, fundCode, queryType, UserUtil.getLoginUserId(), beginNum, requestNum, business, allotNo);
        } catch (Exception e) {
            ExceptionUtil.logError(log, "ruifubaoRecord - Exception:", e);
        }
        return wTradingRecordListResult;
    }
}
